<?php
/**
 *	@package WordPress
 *	@subpackage Carbon_Paper
 */

/**
 *      Template Name: Selection
 *
 */
 

if ( isset( $_POST['action'] ) && $_POST['action'] == 'render_video' ) {
	$aMeta = get_post_meta($_POST['ids'],'_metabox_legrandmix',true);
	$url_video = $aMeta['legrandmix_url_video'];
	$url_video_parts = parse_url($url_video);
//	print_r($url_video_parts);die();
	$url_video_host = $url_video_parts['host'];
	$id = array_pop(explode('/', trim($url_video_parts['path'],'/')));
	switch ($url_video_host){
		default :
			if(function_exists('get_video')){
				//echo '[video]' . $url_video . '[/video]'; exit();
				print get_video('[video]' . $url_video . '[/video]');
				//echo '<iframe id="myvideotag" src="' . $url_video . '?autoplay=1" width="620" height="465" frameborder="0"></iframe>';
				//echo '<i></i>';
			}
		break; 	
	};
	die();
}

if ( isset( $_POST['action'] ) && $_POST['action'] == 'render_content' ) {
	global $wp_query;
	query_posts( $_POST['ids'] );	
	if (have_posts()) : while (have_posts()) : the_post();
		echo get_the_content('',0,'');
	endwhile;endif;	
	die();
}


 
wp_enqueue_style('selection', TEMPLATEURL . 'css/selection.css'); 
wp_enqueue_style('player', TEMPLATEURL . 'css/player.css'); 
wp_enqueue_style('debug', TEMPLATEURL . 'css/debug.css'); 
wp_enqueue_script('soundmanager2', TEMPLATEURL . 'js/soundmanager2.js'); 
wp_enqueue_script('player', TEMPLATEURL . 'js/player.js'); 
add_action('wp_print_footer_scripts', 'do_selection_ajax');
get_header();

function do_selection_ajax() {
?>
<script type="text/javascript">
jQuery(document).ready(function(){
	
	$('#selection .day').click(function() {
		if ($(this).children('.post-body').css('display') == 'none'){
			$('#selection .post-body').slideUp();
			$('#selection .day').css('color','#ccc');
			$(this).css('color','black');
			$(this).children('.post-body').slideDown();
		}
		return false;
	});
	
	jQuery('#selection .video-link').click(function(){
		var data = {
			action: 'render_video',
			ids: jQuery(this).attr("rel") 
	  	};
		jQuery('#selection .content-link').addClass("load");
		jQuery('#post-lead-' + data['ids'] + ' p:first').fadeIn(800).load(jQuery(location).attr('href'),data,function(response) {
			bouton_play();
	  		//alert('Got this from the server: ' + response);
		});
		return false;
    });
});
</script>
<?php
}
?>

<div class="clear"></div>
<div id="cover">&nbsp;</div>

<?php 
global $wp_query;

$args = array(
	'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1, 
	'post_type' => array('le-grand-mix'),
	'orderby' => 'post_type post_date',
	'order' => 'DESC'
	);
query_posts( $args );
?>
<div id="selection">
	<?php global $more; if (have_posts()) : while (have_posts()) : the_post(); ?>
		<?php get_template_part('content','selection');?>
	<?php endwhile; ?>
	<?php if ( function_exists( 'render_pagination' ) ) render_pagination();?>
		<p>&nbsp;</p>
		<div class="clear"></div>
	<?php else : ?>
		<?php get_template_part('content','nomatch');?>
	<?php endif; ?>
</div><!-- /#posts -->


<?php get_template_part('second-column','selection'); ?>
<?php if (!is_category()) : get_template_part('third-column','shared'); endif;?>

<?php get_footer(); ?>
</div><!-- /home or articles -->